﻿using System;
using System.Runtime.InteropServices;

namespace Microsoft.Xna.Framework.Graphics
{
	/// <summary>
	/// Binds an array of render targets.
	/// </summary>
	[StructLayout(LayoutKind.Sequential)]
	public struct RenderTargetBinding
	{
		internal Texture _renderTarget;
		internal CubeMapFace _cubeMapFace;

		#region Properties
		/// <summary>
		/// Gets a 2D texture.
		/// </summary>
		public Texture RenderTarget
		{
			get { return _renderTarget; }
		}

		/// <summary>
		/// Gets one face of a cubemap.
		/// </summary>
		public CubeMapFace CubeMapFace
		{
			get { return _cubeMapFace; }
		}
		#endregion

		#region Constructor
		/// <summary>
		/// Creates an instance of this object.
		/// </summary>
		/// <param name="renderTarget">Identifies a 2D render target.</param>
		public RenderTargetBinding(RenderTarget2D renderTarget)
		{
			if (renderTarget == null)
			{
				throw new ArgumentNullException("renderTarget", FrameworkResources.NullNotAllowed);
			}
			this._renderTarget = renderTarget;
			this._cubeMapFace = CubeMapFace.PositiveX;
		}

		/// <summary>
		/// Creates an instance of this object.
		/// </summary>
		/// <param name="renderTarget">Identifies a cubemap render target.</param>
		/// <param name="cubeMapFace">Cubemap face.</param>
		public RenderTargetBinding(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
		{
			if (renderTarget == null)
			{
				throw new ArgumentNullException("renderTarget", FrameworkResources.NullNotAllowed);
			}
			this._renderTarget = renderTarget;
			this._cubeMapFace = cubeMapFace;
		}
		#endregion

		/// <summary>
		/// 
		/// </summary>
		/// <param name="renderTarget"></param>
		/// <returns></returns>
		public static implicit operator RenderTargetBinding(RenderTarget2D renderTarget)
		{
			return new RenderTargetBinding(renderTarget);
		}
	}
}
